package jw.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * Created by Basil on 2017/1/4.
 */
public class OrderNumberUtil {

    /***
     * 生成订单编号
     * @param orderId 订单自增长的主键
     * @return 订单编号字符串
     */
    public static String createOrderNumber(Integer orderId) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String date = sdf.format(new Date());
        String number = date + orderId;
        return number;
    }

    /**
     * 生成代理商编号
     * @param agentId
     * @return
     */
    public static String createAgentNumber(Integer agentId) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHH");
        String date = sdf.format(new Date());
        String number = date + agentId;
        return number;
    }
    /**
     * 获取订单编号
     * @return
     */
    public static String getRandomFileName() {
        SimpleDateFormat simpleDateFormat;
        simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String str = simpleDateFormat.format(date);
        Random random = new Random();
        int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数
        return "JW"+str+rannum ;// 当前时间 + 系统5随机生成位数
    }
}
